﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Threading.Tasks;
using WMSmanagement.IBaseService.Sale.DTO;
using WMSmanagement.IBaseService.Transfer;
using WMSmanagement.IBaseService.Transfer.DTO;

namespace WMSmanagement.Web.Controllers
{
    public class TransferController1 : Controller
    {
        private readonly ITransferService _transferService;

        public TransferController1(ITransferService transferService)
        {
            _transferService = transferService;
        }

        public IActionResult Show()
        {
            return View();
        }
        public IActionResult Add()
        {
            return View();
        }
        public IActionResult Update()
        {
            return View();
        }
        public async Task<IActionResult> GetTransfer(RequsetTransfer model)
        {
            var list =await _transferService.GetTransferAsync(model);
            return Ok(list);
        }
        public async Task<IActionResult> AddTransfer(AddTransferDTO model)
        {
            model.ids = JsonConvert.DeserializeObject<List<Buyids>>(model.idsString);
            model.ids.ForEach(c =>
            {
                c.Num=model.Quantity;
            });
            var list =await _transferService.AddTransferAsnyc(model);
            return Ok(list);
        } 
        public async Task<IActionResult> UpdateTransfer(UpdateTransferDTO model)
        {
            model.ids = JsonConvert.DeserializeObject<List<Buyids>>(model.idsString);
            model.ids.ForEach(c =>
            {
                c.Num = model.Quantity;
            });
            var list =await _transferService.UpdateTransferAsnyc(model);
            return Ok(list);
        }
        public async Task<IActionResult> DeletesTransfer(string id)
        {
            
            var list =await _transferService.DeleteTransferAsnyc(id);
            return Ok(list);
        }
    }
}
